saveToString

abstract suspend fun saveToString(scene: DesignBlock, allowedResourceSchemes: List<String> = listOf("blob", "bundle", "file", "http", "https")): String

Serializes the current scene into a string. Selection is discarded. If a resource uri has a scheme that is not in allowedResourceSchemes, an exception will be thrown.

The source set entries that the engine makes are buffer:// resources that only this engine holds. The save leaves them out, even when the allowed resource schemes hold "buffer", and each fill keeps them.

Return

a serialized scene string.

Parameters

scene

the scene to serialize.

allowedResourceSchemes

the list of allowed resource schemes in the scene.


abstract suspend fun saveToString(scene: DesignBlock, allowedResourceSchemes: List<String> = listOf("blob", "bundle", "file", "http", "https"), onDisallowedResourceScheme: suspend (uri: Uri, dataHash: String) -> Uri): String

Serializes the current scene into a string, as saveToString does, and passes each resource URI whose scheme is not in allowedResourceSchemes to onDisallowedResourceScheme instead of throwing. Selection is discarded. Cancelling the coroutine stops the save and the callbacks that still run.

The source set entries that the engine makes are buffer:// resources that only this engine holds. onDisallowedResourceScheme gets each of them, whatever allowedResourceSchemes holds. The save leaves out each entry that the callback did not move to another address, and each fill keeps them.

Return

a serialized scene string.

Parameters

scene

the scene to serialize.

allowedResourceSchemes

the list of allowed resource schemes in the scene.

onDisallowedResourceScheme

called on the engine thread for each resource URI with a scheme absent from allowedResourceSchemes, with the URI and the hash of the resource's data. It returns the URI that the saved scene uses for the resource, or the URI it got when the resource needs no other address. The save waits for each answer. When the callback throws, the save fails with an EngineException of code EngineErrorCode.BINDING_HOST_CALLBACK_THREW.


abstract suspend fun saveToString(scene: DesignBlock, options: SaveToStringOptions): String

Serializes the current scene into a string with optional compression. Selection is discarded. If a resource uri has a scheme that is not in options.allowedResourceSchemes, an exception will be thrown.

While a font loads, its text is laid out with another font. When the text's size follows its content, a scene saved before the font arrives can differ from one saved after it. To compare two saved scenes, first call engine.block.forceLoadResources(listOf(scene)). It throws when a resource fails to load, and you can still save the scene then.

The source set entries that the engine makes are buffer:// resources that only this engine holds. The save leaves them out, even when the allowed resource schemes hold "buffer", and each fill keeps them.

The string is a container, not JSON: a four-character format prefix followed by a base64 payload. With the default CompressionFormat.ZSTD the prefix is UBQ2 and the payload is a Zstd frame. With CompressionFormat.NONE the prefix is UBQ1 and the payload is the scene JSON. Loading accepts both, so tooling that reads the decoded payload must handle both forms.

Return

a serialized scene string.

Parameters

scene

the scene to serialize.

options

save options containing:

  • allowedResourceSchemes: The list of allowed resource schemes in the scene. Defaults to "blob", "bundle", "file", "http", "https". Add "data" to keep data: URIs.

  • compression: Optional compression settings containing:

    • format: Compression format (NONE or ZSTD). Defaults to ZSTD.

    • level: Compression level (FASTEST, DEFAULT, or BEST). Defaults to DEFAULT.